import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:life_service/model/hotel.dart';
import 'package:scrollview_observer/scrollview_observer.dart';

class HotelListController extends GetxController {
  List<String> selected = ['位置区域', '价格等级', '智能排序', '筛选'];

  List<String> price = [
    '￥0-50',
    '￥150-300',
    '￥300-450',
    '￥450-600',
    '¥600-1000',
    '￥1000以上'
  ];

  RxString tag = '文本标签'.obs;

  RxInt tagIdx = RxInt(-1);

  List<String> hotel = ['经济型', '舒适性', '高档型', '豪华型'];

  RxInt hotelIdx = RxInt(-1);

  List<String> sort = ['综合排序', '好评优先', '低价优先', '高价优先', '人气优先'];

  RxInt screenIdx = RxInt(-1);

  List<String> screen = [
    '经济连锁',
    '民宿',
    '公寓',
    '青年旅社',
    '主题酒店',
    '商务酒店',
    '温泉酒店',
    '家庭旅馆',
    '中端连锁'
  ];

  List<Rx<HotelTypeModel>> types = [
    Rx(HotelTypeModel(name: '新人立减')),
    Rx(HotelTypeModel(name: '含早')),
    Rx(HotelTypeModel(name: '4.8分以上')),
  ];

  final GlobalKey appBarKey = GlobalKey();

  final int total = 46;

  int page = 1;

  final int size = 10;

  RxInt pageSize = 10.obs;

  RxBool isLoading = false.obs;

  void loadMore() {
    Get.engine.addPostFrameCallback((_) async {
      isLoading.value = true;
      await Future.delayed(const Duration(seconds: 4));
      page++;
      pageSize.value = size * page;
      isLoading.value = false;
    });
  }
}

class HotelMainController extends GetxController
    with GetTickerProviderStateMixin {
  late ScrollController scrollController;

  late ListObserverController observerController;

  late TabController tabController;

  late AnimationController animationController;

  List<String> tabs = ['酒店预订', '酒店设施', '住客评论', '热门酒店'];

  List<int> tabIndexs = [0, 1, 2, 3];

  List<String> tags = ['会员价', '新人红包'];

  @override
  void onInit() {
    scrollController = ScrollController();
    observerController = ListObserverController(controller: scrollController);
    tabController = TabController(length: tabs.length, vsync: this);
    animationController = AnimationController(
      duration: const Duration(milliseconds: 300),
      vsync: this,
    );
    super.onInit();
  }

  @override
  void onClose() {
    scrollController.dispose();
    // observerController.controller?.dispose();
    tabController.dispose();
    animationController.dispose();
    super.onClose();
  }
}

class HotelInfoController extends GetxController
    with GetTickerProviderStateMixin {
  late ScrollController scrollController;

  late ListObserverController observerController;

  late TabController tabController;

  List<String> tabs = ['酒店信息', '设施服务', '入住须知', '交通娱乐'];

  List<int> tabIndexs = [0, 1, 2, 3];

  List<String> tags = ['交通', '景点', '餐饮', '购物'];

  RxInt tagIdx = RxInt(0);

  @override
  void onInit() {
    scrollController = ScrollController();
    observerController = ListObserverController(controller: scrollController);
    tabController = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    scrollController.dispose();
    tabController.dispose();
    super.onClose();
  }
}

class HotelCommentController extends GetxController
    with GetTickerProviderStateMixin {
  late TabController tabController;

  final List<String> tabs = <String>['全部(926)', '好评(600)', '中评(300)', '差评(9)'];

  @override
  void onInit() {
    tabController = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    tabController.dispose();
    super.onClose();
  }
}

class HotelOrderController extends GetxController {}

class HotelPayController extends GetxController {
  List<Rx<HotelPayModel>> pays = [
    HotelPayModel(name: '支付宝支付', svgName: 'u3001', checed: true).obs,
    HotelPayModel(name: '微信支付', svgName: 'u3009').obs,
    HotelPayModel(name: '招商卡支付', svgName: 'u3014').obs,
    HotelPayModel(name: '余额支付', svgName: 'u9001').obs,
  ];
}

class HotelSuccessController extends GetxController {}
